﻿using JuCheap.Core.Infrastructure;
using JuCheap.Core.IService;
using JuCheap.Core.Model;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace JuCheap.Core.WebApi.Controllers
{
    /// <summary>
    /// 日志服务api
    /// </summary>
    [Route("api/[controller]")]
    public class LogController : BaseApiController
    {
        private readonly ISysLogQueryService _sysLogQueryService;

        /// <summary>
        /// ctor
        /// </summary>
        public LogController(ISysLogQueryService sysLogQueryService)
        {
            _sysLogQueryService = sysLogQueryService;
        }

        /// <summary>
        /// 分页获取登录日志信息
        /// </summary>
        [HttpPost]
        [Route("login/search")]
        public async Task<ActionResult<PagedResult<SysLoginLogDto>>> SearchLoginLogs([FromBody]SysLoginLogFilter filter)
        {
            var records = await _sysLogQueryService.QueryLoginLogsPagesAsync(filter);
            return Ok(records);
        }

        /// <summary>
        /// 分页获取访问日志信息
        /// </summary>
        [HttpPost]
        [Route("visit/search")]
        public async Task<ActionResult<PagedResult<SysVisitLogDto>>> SearchVisitLogs([FromBody]SysVisitLogFilter filter)
        {
            var records = await _sysLogQueryService.QueryVisitLogsPagesAsync(filter);
            return Ok(records);
        }
    }
}
